/*
 * Copyright (c) 2023 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef _INTERFACE_I2C_H_
#define _INTERFACE_I2C_H_

#include "internal/bus/bus_i2c/i2c.h"
#include <device_tree/interface/Bus/I2c.h>
#include <mc/engine.h>

namespace dev {

// I2C 默认值常量
constexpr uint32_t I2C_DEFAULT_SPEED      = 100;
constexpr uint8_t  I2C_DEFAULT_MODE       = 0;
constexpr uint8_t  I2C_DEFAULT_SLAVE_ADDR = 0;
constexpr bool     I2C_DEFAULT_USE_SMBUS  = false;

class Interface_I2c : public mc::engine::interface<Interface_I2c, gen::I2c> {
public:
    Interface_I2c() {
        // 使用默认值初始化成员变量
        Speed     = I2C_DEFAULT_SPEED;
        Mode      = I2C_DEFAULT_MODE;
        SlaveAddr = I2C_DEFAULT_SLAVE_ADDR;
        UseSmbus  = I2C_DEFAULT_USE_SMBUS;
    }
    ~Interface_I2c() = default;

    // 从variant中加载配置到基类属性
    void from_variant(mc::mutable_dict& csr_object);

    // I2C速度转换函数
    uint32_t get_i2c_speed(uint32_t speed);

    bus_i2c* m_bus_i2c = nullptr;
};

} // namespace dev

#endif // _INTERFACE_I2C_H_